package edu.cuit.avatar;

import java.time.*;
import java.util.Date;
import java.util.Scanner;

/**
 * jdk8以后提供了时间内库：具有更加清晰的语义及相关操作
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/4 11:26
 */
public class Date8Test {
    public static void main(String[] args) {
        //系统当前日期
        LocalDate now = LocalDate.now();
        System.out.println(now.toString()); //2025-07-04

        //日期相关api
        System.out.println("is leap year:" + now.isLeapYear());
        LocalDate date = now.plusDays(10);
        System.out.println(date);

        System.out.println(now.isAfter(date));//false
        System.out.println(now.isBefore(date)); //true

        //创建指定日期的LocalDate对象
        LocalDate bornDate = LocalDate.of(2016, 10, 20);
        System.out.println(bornDate.isBefore(now)); //true

        //将字符串转为LocalDate
        System.out.println("请输入你的出生日期(e.g: 2000-10-20)");
        Scanner input = new Scanner(System.in);

        String birthday = input.nextLine();

        LocalDate date1 = LocalDate.parse(birthday);
        System.out.println(date1.isLeapYear());

        //兼容java8以前的Date(相互转换) Date ===> LocalDate
        Date date2 = new Date();
        Instant instant = date2.toInstant();
        LocalDate date3 = LocalDate.ofInstant(instant, ZoneId.systemDefault());

        //日期时间
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime);

        LocalTime time = LocalTime.now();
        System.out.println(time);

        //用户注册了信息(生日),判断是否为生日月
    }
}
